
ac.loop(1000,function()
    ac.each_player(function(player)
        local hero = player.hero
        local change = player:get_data('累计显示金币',0)
        player:set_data('累计显示金币',0)
        if hero and change>0 then
            ac.texttag {
                text = ('|cffffff00%0.f|n'):format(change),
                font_size = 36,
                angle = 90,
                speed = 100,
                lifespan = 1,
                fadepoint = 0.5,
                target = hero:get_point(),
            }
        end
    end)
end)

--带图标的资源
function ac.player.__index:add_icon(name,num,target)
    local unit = target or self.hero
    local text = num
    local icon = ''
    local point = unit:get_point()
    if name=='金币' then
        text = ('|cffffff00+%0.f|r'):format(num)
        icon = [[UI\Feedback\Resources\ResourceGold.blp]]
        point.z = point.z + 200
    end
    if name=='木材' then
        text = ('|cff00ff00+%0.f|r'):format(num)
        icon = [[UI\Feedback\Resources\ResourceLumber.blp]]
        point.z = point.z + 100
    end
    if name=='杀敌' then
        text = ('|cffff0000+%0.f|r'):format(num)
        icon = [[UI\Feedback\Resources\ResourceSupply.blp]]
    end
    if icon~='' then
        ac.icon_tag {
            text = text,
            speed = 80,
            life = 1,
            fade = 0.5,
            scale = 1,
            point = point,
            icon = icon,
        }
    end
    self:add(name,num)
end

ac.game:event '单位-死亡'(function(_,unit,killer)
    local player = unit.owner_player
    if not player then
        return
    end
    local hero = player.hero
    if not hero then
        return
    end
    local name = unit.name
    local point = unit:get_point()
    local gold = unit['金币'] or 0
    local exp = unit['经验'] or 0
    local kill = unit['杀敌'] or 1
    local lumber = unit['木材'] or 0
    hero:add_exp(tonumber(exp) or 0)
    hero:notify('英雄-击杀单位',hero,unit)
    unit:notify('单位-被英雄击杀',hero,unit)

    if lumber and lumber>0 then
        player:add_icon('木材',lumber,unit)
    end
    if gold and gold>0 then
        player:add_icon('金币',gold,unit)
    end

    if kill and kill>1 then
        player:add_icon('杀敌',kill,unit)
    else
        player:add('杀敌',kill)
    end
    if name=='塔2' then
        player:notify('玩家-武器觉醒',player)
    end
    if name=='恶魔右使' then
        ac.item.create('魔界之火',point,{owner_player = player})
        point:effect{
            model = [[Objects\Spawnmodels\Undead\UndeadLargeDeathExplode\UndeadLargeDeathExplode.mdl]],
            time = 1,
        }
        unit:remove()
    end
    if name=='恶魔左使' then
        ac.item.create('狱岩石',point,{owner_player = player})
    end
    if name=='炽魔王' then
        ac.item.create('魔王之魂',point,{owner_player = player})
    end
    
    player:set_data('总杀敌',player:get_data('总杀敌',0) + 1)
    
end)